/*
 * @Description: 描述信息
 * @Version: 版本号
 * @Author: xuebao
 * @Date: 2023-12-12 11:51:48
 * @LastEditors: xuebao
 * @LastEditTime: 2023-12-12 12:17:44
 */
import * as echarts from 'echarts'
import { useEffect, useRef, useState, RefObject } from 'react'

export const useCharts = (): [RefObject<HTMLDivElement>, echarts.EChartsType | undefined] => {
  const chartRef = useRef<HTMLDivElement>(null) //创建了一个ref
  const [chartInstance, setChartInstance] = useState<echarts.EChartsType>()
  useEffect(() => {
    const chart = echarts.init(chartRef.current as HTMLElement)
    setChartInstance(chart)
  }, [])
  return [chartRef, chartInstance]
}
